package com.dev.security.login.service.filters;

import org.apache.commons.lang3.StringUtils;

import com.dev.security.login.service.ValidateFilter;
import com.dev.security.login.service.ValidateInvocation;
import com.dev.security.login.util.LoginConstants;

/**
 * @author 潜行的青衣
 * @see
 */
public class NoLoginFilter implements ValidateFilter  {

	/* (non-Javadoc)
	 * @see com.dev.security.login.service.ValidateFilter#filter(com.dev.security.login.service.ValidateInvocation)
	 */
	@Override
	public int filter(ValidateInvocation invoc) {
		//资源存在的链接
		if(invoc.getLoginUser() == null) {
			return LoginConstants.VALIDATE_NOLOGIN;
		}
		//只需要登录的链接
		if(StringUtils.endsWithIgnoreCase(
				LoginConstants.TYPE_NEED_LOGIN, invoc.getLoginSource().getType())) {
			return LoginConstants.VALIDATE_TRANSIT;
		}
		//需要继续判定权限的链接
		return invoc.invoke();
	}

}
